//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2010 Greenplum, Inc.
//
//	@filename:
//		CDXLTranslateContextBaseTable.h
//
//	@doc:
//		Class providing access to translation context for translating base table
//		column references, such as mappings from a DXL ColId to a SPQDB attribute number in
//		the base table schema
//
//	@test:
//
//
//---------------------------------------------------------------------------

#ifndef SPQDXL_CDXLTranslateContextBaseTable_H
#define SPQDXL_CDXLTranslateContextBaseTable_H

#include "postgres.h"  // Index

#include "spqos/base.h"
#include "spqos/common/CHashMap.h"

#include "naucrates/dxl/spqdb_types.h"

namespace spqdxl
{
using namespace spqos;


//---------------------------------------------------------------------------
//	@class:
//		CDXLTranslateContextBaseTable
//
//	@doc:
//		Class providing access to translation context, such as mappings between
//		ColIds and target entries
//
//---------------------------------------------------------------------------
class CDXLTranslateContextBaseTable
{
	// hash maps mapping ULONG -> INT
	typedef CHashMap<ULONG, INT, spqos::HashValue<ULONG>, spqos::Equals<ULONG>,
					 CleanupDelete<ULONG>, CleanupDelete<INT> >
		UlongToIntMap;


private:
	CMemoryPool *m_mp;

	// oid of the base table
	OID m_oid;

	// index of the relation in the rtable
	Index m_rel_index;

	// maps a colid of a column to the attribute number of that column in the schema of the underlying relation
	UlongToIntMap *m_colid_to_attno_map;

	// private copy ctor
	CDXLTranslateContextBaseTable(const CDXLTranslateContextBaseTable &);

public:
	// ctor/dtor
	explicit CDXLTranslateContextBaseTable(CMemoryPool *mp);


	~CDXLTranslateContextBaseTable();

	// accessors
	OID GetOid() const;

	Index GetRelIndex() const;

	// return the index of the column in the base relation for the given DXL ColId
	INT GetAttnoForColId(ULONG dxl_colid) const;

	// setters
	void SetOID(OID oid);

	void SetRelIndex(Index rel_index);

	// store the mapping of the given DXL column id and index in the base relation schema
	BOOL InsertMapping(ULONG dxl_colid, INT att_no);
};
}  // namespace spqdxl

#endif	// !SPQDXL_CDXLTranslateContextBaseTable_H

// EOF
